<div class="sm-pop">
    <div id="dialog_form" class="layui-form">
        <div class="layui-form-item" style="display: none;">
            <input type="hidden" name="userId" value="<%=userId%>">
            <input type="hidden" name="roleId" value="<%=roleId%>">
            <div class="layui-inline">
                <button class="layui-btn"><i class="iconfont icon-sousuo"></i>查询</button>
            </div>
        </div>
    </div>
    <table id="role_list" class="layui-hide" lay-filter="role_list"></table>
</div>
<script>
    layui.use(['layer', 'table', 'form'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;

        //表单重新渲染
        form.render();

        //表格渲染
        var tableObj = table.render({
            id: 'role_list'
            , elem: '#role_list'
            , url: '/sys/user/role/list'
            , align: "center"
            , cols: [[ //表头
                {checkbox:true}
                , {field: 'roleName', title: '角色名', width: 120, align: 'center'}
                , {field: 'remark', title: '备注', width: 170, align: 'center'}
            ]],where:{"userId":$(".sm-pop input[name=userId]").val()},
            page:false,
            done:function () {
                var data = table.checkStatus('role_list').data;
                var arr=[]
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].roleId);
                }
                $(".sm-pop input[name=roleId]").val(arr.join(","));
            }
        });

        table.on('checkbox(role_list)', function(obj){ // 监听复选框事件
            var data = table.checkStatus('role_list').data;
            var arr=[]
            for (var i = 0; i < data.length; i++) {
                arr.push(data[i].roleId);
            }
            $(".sm-pop input[name=roleId]").val(arr.join(","));
        });
    });
</script>